import interfaces.ICard;
import interfaces.IPlayer;
import structs.Card;
import structs.Game;
import structs.Player;

/**
 * Clase principal de juego de Briscas.
 * @author Xavier
 *
 */
public class Briscas {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Instructions.generateInstructionSet();
		BriscasMatch.getInstance().startGame();	
		
	}
	
	public void oldmain(String[] args) {
		Game game = null;
		
		try {
			game = new Game(2,2);
		} catch (Exception e) {
			e.printStackTrace();
		}

		game.getDeck().setLife(new Card("Oro",7,0));
		
		//First 
		Player ai = (Player) game.getAIPlayer();
		ai.addCard(new Card("Copa",1,11));
		ai.addCard(new Card("Copa",5,0));
		ai.addCard(new Card("Espada",12,4));
		
		String stsM = game.start();
		
		System.out.println(stsM);
		
//		if(!stsM.isEmpty()){
//			//Check for objections
//			game.getAIPlayer().swapLife();
//		}
//		
//		System.out.println("New life: " + game.getDeck().getLife().getSuit() + " " + game.getDeck().getLife().getNumber());
//		System.out.println("");
		
		
		//Let's play
		System.out.println("Round 1: ");

		while(!game.nextHasMove()){
			game.getCurrentPlayer().setPlayedCard(new Card("Copa",11,3));
			game.addCurrentPlay(new Card("Copa",11,3));
			System.out.println("Player 1: " + game.getCurrentPlayer().getPlayedCard().getSuit() + " " + game.getCurrentPlayer().getPlayedCard().getNumber());
			game.next();
		}
		
		if(game.nextHasMove()){
			ICard c = game.getAIPlayer().getNextMove();
			System.out.println("Player 2: " + c.getSuit() + " " + c.getNumber());
			game.addCurrentPlay(c);
		}
		
		while(game.next()){
			//Nothing next here
		}
		
		System.out.println("Winner is " + game.roundOver());
		
		if(!game.hasEnded()){
			System.out.println("");
		}
		
		
		//Now let' go to second round
		System.out.println("Round 2:");
		
		ai.addCard(new Card("Oro",10,3));
		
		while(!game.nextHasMove()){

		}
		
		if(game.nextHasMove()){
			ICard c = game.getAIPlayer().getNextMove();
			System.out.println("Player 2: " + c.getSuit() + " " + c.getNumber());
			game.addCurrentPlay(c);
		}
		
		while(game.next()){
			game.getCurrentPlayer().setPlayedCard(new Card("Oro",11,3));
			game.addCurrentPlay(new Card("Oro",11,3));
			System.out.println("Player 1: " + game.getCurrentPlayer().getPlayedCard().getSuit() + " " + game.getCurrentPlayer().getPlayedCard().getNumber());
		}
		
		System.out.println("Winner is " + game.roundOver());
		
		if(!game.hasEnded()){
			System.out.println("");
		}
				
		//Now let' go to third round
		System.out.println("Round 3:");

		ai.addCard(new Card("Espada",5,0));
		
		while(!game.nextHasMove()){
			game.getCurrentPlayer().setPlayedCard(new Card("Basto",1,11));
			game.addCurrentPlay(new Card("Basto",1,11));
			System.out.println("Player 1: " + game.getCurrentPlayer().getPlayedCard().getSuit() + " " + game.getCurrentPlayer().getPlayedCard().getNumber());
			game.next();
		}
		
		if(game.nextHasMove()){
			ICard c = game.getAIPlayer().getNextMove();
			System.out.println("Player 2: " + c.getSuit() + " " + c.getNumber());
			game.addCurrentPlay(c);
		}
		
		while(game.next()){
			
		}
		
		System.out.println("Winner is " + game.roundOver());

		
		if(!game.hasEnded()){
			System.out.println("");
		}
		
		
		//Now let' go to fourth round
		System.out.println("Round 4:");
		
		ai.addCard(new Card("Copa",6,0));
		
		while(!game.nextHasMove()){

		}
		
		if(game.nextHasMove()){
			ICard c = game.getAIPlayer().getNextMove();
			System.out.println("Player 2: " + c.getSuit() + " " + c.getNumber());
			game.addCurrentPlay(c);
		}
		
		while(game.next()){
			game.getCurrentPlayer().setPlayedCard(new Card("Espada",3,10));
			game.addCurrentPlay(new Card("Espada",3,10));
			System.out.println("Player 1: " + game.getCurrentPlayer().getPlayedCard().getSuit() + " " + game.getCurrentPlayer().getPlayedCard().getNumber());
		}
		
		System.out.println("Winner is " + game.roundOver());
		
		if(!game.hasEnded()){
			System.out.println("");
		}
		
		//Now let' go to fifth round
		System.out.println("Round 5:");
		
		ai.addCard(new Card("Espada",1,11));
		
		while(!game.nextHasMove()){
			//In this case the above condition is false
			game.getCurrentPlayer().setPlayedCard(new Card("Copa",7,0));
			game.addCurrentPlay(new Card("Copa",7,0));
			System.out.println("Player 1: " + game.getCurrentPlayer().getPlayedCard().getSuit() + " " + game.getCurrentPlayer().getPlayedCard().getNumber());
			game.next();
		}
		
		if(game.nextHasMove()){
			ICard c = game.getAIPlayer().getNextMove();
			System.out.println("Player 2: " + c.getSuit() + " " + c.getNumber());
			game.addCurrentPlay(c);
		}
		
		while(game.next()){
			
		}
		
		System.out.println("Winner is  " + game.roundOver());

		if(!game.hasEnded()){
			System.out.println("");
		}
		
		//Now let' go to sixth round
		System.out.println("Round 6:");
		
		ai.addCard(new Card("Espada",4,0));
		
		while(!game.nextHasMove()){
			//In this case the above condition is false
			game.getCurrentPlayer().setPlayedCard(new Card("Basto",10,2));
			game.addCurrentPlay(new Card("Basto",10,2));
			System.out.println("Player 1: " + game.getCurrentPlayer().getPlayedCard().getSuit() + " " + game.getCurrentPlayer().getPlayedCard().getNumber());
			game.next();
		}
		
		if(game.nextHasMove()){
			ICard c = game.getAIPlayer().getNextMove();
			System.out.println("Player 2: " + c.getSuit() + " " + c.getNumber());
			game.addCurrentPlay(c);
		}
		
		while(game.next()){
			
		}
		
		System.out.println("Winner is  " + game.roundOver());

		if(!game.hasEnded()){
			System.out.println("");
		}
		
		//Now let' go to seventh round
		System.out.println("Round 7:");
		
		ai.addCard(new Card("Espada",6,0));
		
		while(!game.nextHasMove()){
			//In this case the above condition is false
			game.getCurrentPlayer().setPlayedCard(new Card("Oro",1,11));
			game.addCurrentPlay(new Card("Oro",1,11));
			System.out.println("Player 1: " + game.getCurrentPlayer().getPlayedCard().getSuit() + " " + game.getCurrentPlayer().getPlayedCard().getNumber());
			game.next();
		}
		
		if(game.nextHasMove()){
			ICard c = game.getAIPlayer().getNextMove();
			System.out.println("Player 2: " + c.getSuit() + " " + c.getNumber());
			game.addCurrentPlay(c);
		}
		
		while(game.next()){
			
		}
		
		System.out.println("Winner is  " + game.roundOver());

		if(!game.hasEnded()){
			System.out.println("");
		}
		
		if(!game.hasEnded()){
						
			System.out.println("");

			System.out.println("Totals");

			for(IPlayer player : game.getPlayers()){
				System.out.println( player.getName()+ ": " + player.getWinStackPoints());
			}

		}
		
	}

}
